---武器技能 创建系统
IteamUsed = {}
---所有装备
AllItems={}
---套装
IteamSuits={}
---套装加成
IteamSuitsAttr={}
---技能存放
IteamUsedSkill={}


---作用目标
TARGET_LABEL = {
    notself = "notself",--"别人",
    debris = "debris",--"残骸",
    alive = "alive",--"存活",
    ground = "ground",--"地面",
    terrain = "terrain",--"地形",
    enemies = "enemies",--"敌人",
    enemy = "enemy",--"敌人",
    ancient = "ancient",--"古树",
    mechanical = "mechanical",--"机械类",
    structure = "structure",--"建筑",
    vuln = "vuln",--"可攻击的",
    air = "air",--"空中",
    allies = "allies",--"联盟",
    none = "none",--"没有",
    well = "well",--"墙",
    bridge = "bridge",--"桥",
    ward = "ward",--"守卫",
    tree = "tree",--"树木",
    dead = "dead",--"死亡",
    player = "player",--"玩家单位",
    invu = "invu",--"无敌",
    item = "item",--"物品",
    hero = "hero",--"英雄",
    friend = "friend",--"友军",
    organic = "organic",--"有机生物",
    neutral = "neutral",--"中立",
    decoration = "decoration",--"装饰物",
    sapper = "sapper",--"自爆工兵",
    self = "self",--"自己",
    nonancient = "nonancient",--"非古树",
    nonhero = "nonhero",--"非英雄",
    nonsapper = "nonsapper",--"非自爆兵",
}

---@param fun onItemUsed | "function(evtData) end"
function IteamUsed:Skill(key, fun)
    IteamUsedSkill[key] = fun
end
---施放技能
---@param _v {triggerUnit:"触发单位",triggerItem:"触发物品",triggerSkill:"施放技能ID字符串",targetUnit:"获取目标单位",targetX:"获取施放目标点X",targetY:"获取施放目标点Y",targetZ:"获取施放目标点Z"}
function IteamUsed:Use(_v)
    if IteamUsedSkill ~= nil and IteamUsedSkill[_v.triggerItem] ~= nil then
        IteamUsedSkill[_v.triggerItem](_v)
    else
        echo("无技能", hunit.getOwner(_v.targetUnit))
    end
end
function IteamUsed:AllUse()
    local Used =
        _onItemUsed(
        function(evtData)
            self:Use(evtData)
            
        end
    )
    return Used
end
---根据物品ID获取套装名字
function IteamUsed:getSuitKey(key)
    return string.match(hitem.getName(key), "(.+套%-)")
end
---根据物品名字获取套装名字
function IteamUsed:getSuitName(name)
    return string.match(name, "(.+套%-)")
end
---技能无目标
function IteamUsed:hslk_item(items)
    if self.Used == nil then
        self.Used = {}
    end
    for i, v in ipairs(items) do
        v.Name = v.Name or "无名_" .. i
        v.class = v.class or CONST_ITEM_CLASS.Permanent
        ---提示
        v.Ubertip = v.Ubertip or "无提示"
        ---黄金消耗
        v.goldcost = v.goldcost or 0
        ---木材消耗
        v.lumbercost = v.lumbercost or 0
        ---捡起自动使用
        v.powerup = v.powerup or 0
        ---可被市场出售
        v.sellable = v.powerup or 1
        ---可被抵押
        v.pawnable = v.pawnable or 1
        ---可被丢弃
        v.droppable = v.droppable or 1
        ---使用后消失
        v.perishable = v.perishable or 0
        ---等级
        v.Level = v.Level or 1
        ---技能释放 目标
        v._cooldownTarget = v._cooldownTarget or CONST_ABILITY_TARGET.none.value
        ---技能冷却
        v._cooldown = v._cooldown or 1
        ---堆叠
        -- v._overlie = v._overlie or 1
        ---重量
        v._weight = v._weight or 0
        ---评论
        v._remarks = v._remarks or "无评论"
        
        ---单位使用物品
        v._onItemUsed = v._onItemUsed or self:AllUse()
        table.insert(AllItems, v)

        local taoName=string.match(v.Name,'(.+套%-)')
        if taoName~=nil then
            if IteamSuits[taoName]==nil then
                IteamSuits[taoName]={}
            end
            table.insert(IteamSuits[taoName],v.Name)
            IteamSuitsAttr[taoName]={}
        end
        hslk_item(v)
    end
end



